﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TradeForm
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void miNewDoc_Click(object sender, EventArgs e)
        {

            //FrmTradeForm tf = new FrmTradeForm();
            //tf.MdiParent = this;
            //tf.Show();

            NewDoc();
        }

        private void NewDoc()
        {
            FrmTradeForm frmTadeForm = null;
            foreach (var item in this.MdiChildren)
            {
                if (typeof(FrmTradeForm) == item.GetType())
                {
                    frmTadeForm = (FrmTradeForm)item;
                    break;
                }
            }
            if (frmTadeForm == null)
            {
                frmTadeForm = new FrmTradeForm();
            }
            frmTadeForm.MdiParent = this;
            frmTadeForm.Show();
        }

        private void miOpenDoc_Click(object sender, EventArgs e)
        {
            OpenDoc();
        }

        private void OpenDoc()
        {
            FrmBillBrowser frm = null;
            foreach (var item in this.MdiChildren)
            {
                if (typeof(FrmBillBrowser) == item.GetType())
                {
                    frm = (FrmBillBrowser)item;
                    break;
                }
            }
            if (frm == null)
            {
                frm = new FrmBillBrowser();
            }
            frm.MdiParent = this;
            frm.Show();
        }

        private void miPrintSetting_Click(object sender, EventArgs e)
        {
            config.FrmPosSettings frm = null;
            foreach (var item in this.MdiChildren)
            {
                if (typeof(config.FrmPosSettings) == item.GetType())
                {
                    frm = (config.FrmPosSettings)item;
                    break;
                }
            }
            if (frm == null)
            {
                frm = new config.FrmPosSettings();
            }
            frm.MdiParent = this;
            frm.Show();
        }

        private void miPrint_Click(object sender, EventArgs e)
        {
            if (!(this.ActiveMdiChild is FrmTradeForm))
            {
                MessageBox.Show("先打开单证。", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                FrmTradeForm frmbill = (FrmTradeForm)this.ActiveMdiChild;
                if (!frmbill.IsNew)
                {
                    FrmPrint frmPrint = new FrmPrint(frmbill.DefCode);
                    frmPrint.Show();
                }
                else
                {
                    MessageBox.Show("请先保存数据。", "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

            }
        }

        private void miExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void miBaseInfo_Click(object sender, EventArgs e)
        {
            FrmCompanyInfo frm = null;
            foreach (var item in this.MdiChildren)
            {
                if (typeof(FrmCompanyInfo) == item.GetType())
                {
                    frm = (FrmCompanyInfo)item;
                    break;
                }
            }
            if (frm == null)
            {
                frm = new FrmCompanyInfo();
            }
            frm.MdiParent = this;
            frm.Show();
        }

        private void miModiPwd_Click(object sender, EventArgs e)
        {
            FrmModifyPwd frm = null;
            foreach (var item in this.MdiChildren)
            {
                if (typeof(FrmModifyPwd) == item.GetType())
                {
                    frm = (FrmModifyPwd)item;
                    break;
                }
            }
            if (frm == null)
            {
                frm = new FrmModifyPwd();
            }
            frm.MdiParent = this;
            frm.Show();
        }

        private void tStripBtnNew_Click(object sender, EventArgs e)
        {
            NewDoc();
        }

        private void tStripBtnOpen_Click(object sender, EventArgs e)
        {
            OpenDoc();
        }


    }
}
